﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.Reflection;
using App.Common;
using QxFramework.Core;
public class BuffManager : LogicModuleBase, IBuffManager
{

    /// <summary>
    /// 添加MonoBuff
    /// </summary>
    /// <param name="mono"></param>
    public void AddBuff(Mono mono, int buffID, int Num)
    {
        int tempOverride = 0;
        Buff b = new Buff();
        //有就 叠加+初始化时间
        if (mono.BuffList.ContainsKey(buffID))
        {
            tempOverride = mono.BuffList[buffID].buffOverride.CurrentOverride;
            if (mono.BuffList[buffID].buffOverride.CurrentOverride< mono.BuffList[buffID].buffOverride.MaxOverride)
            {
                mono.BuffList[buffID].buffOverride.CurrentOverride += Num;
                if(mono.BuffList[buffID].buffOverride.CurrentOverride > mono.BuffList[buffID].buffOverride.MaxOverride)
                {
                    mono.BuffList[buffID].buffOverride.CurrentOverride = mono.BuffList[buffID].buffOverride.MaxOverride;
                }
            }
            mono.BuffList[buffID].buffTime.LastingTime = Data.Instance.TableAgent.GetFloat("AllBuff", buffID.ToString(), "LastingTime") + mono.buffStatus.BuffAttrLastTime;
            mono.BuffList[buffID].buffTime.CurrentTime = 0;
        }
        //没有就加一个新的
        else
        {
            mono.BuffList.Add(buffID, GetInitBuff(mono, buffID, Num));
        }
        //特效
        for(int i=1; i <= Num; i++)
        {
            if(i+ tempOverride <= mono.BuffList[buffID].buffOverride.MaxOverride)
            {
                AddEffectMono(Data.Instance.TableAgent.GetString("AllBuff", buffID.ToString(), "Effect"), mono, buffID);
            }
        }
        BuffAffect(mono, buffID);
    }
    public void AddBuff(SceneMonoData scenemono,int buffID)
    {
        BuffAffect(scenemono, buffID);
    }
    public Buff GetInitBuff(Mono mono, int buffID, int Num)
    {
        Buff b = new Buff();
        b.BuffID = buffID;
        b.BuffEffect = Data.Instance.TableAgent.GetString("AllBuff", buffID.ToString(), "Func");
        b.buffOverride.MaxOverride = Data.Instance.TableAgent.GetInt("AllBuff", buffID.ToString(), "MaxOverride");
        b.buffOverride.CurrentOverride = Num;
        b.buffTime.LastingTime = Data.Instance.TableAgent.GetFloat("AllBuff", buffID.ToString(), "LastingTime") + mono.buffStatus.BuffAttrLastTime;
        b.buffTime.CurrentTime = 0;
        return b;
    }

    /// <summary>
    /// 移除Buff
    /// </summary>
    /// <param name="mono"></param>
    public void RemoveBuff(Mono mono,int buffID)
    {
        if (mono.BuffList.ContainsKey(buffID))
        {
            mono.BuffList.Remove(buffID);
        }
    }

    public override void FixedUpdate()
    {
        base.FixedUpdate();
        RefreshAllBuffs();
    }

    /// <summary>
    /// 检测buff时效及生效
    /// </summary>
    /// <param name="mono"></param>
    public void RefreshAllBuffs()
    {
        foreach (Mono m in GameMgr.Get<IMonoManager>().GetAllMono()._MonoList.Values)
        {
            if (m.BuffList.Count == 0)
            {
                continue;
            }
            foreach (Buff buff in m.BuffList.Values)
            {
                if (buff.buffTime.CurrentTime >= buff.buffTime.LastingTime)
                {
                    RemoveBuff(m, buff.BuffID);
                    return;
                }
                else
                {
                    if (GameMgr.Get<ITimeManager>().IsTimeGoing() && GameMgr.Get<IMonoManager>().GetObj(m).GetComponent<MonoBase>().ItsYourTurn())
                    {
                        buff.buffTime.CurrentTime += Time.deltaTime;
                    }
                }
            }
        }
    }

    /// <summary>
    /// Buff生效Mono
    /// </summary>
    public void BuffAffect(Mono mono,int buffID)
    {
        string Func = Data.Instance.TableAgent.GetString("AllBuff", buffID.ToString(), "Func");
        if (Func == "")
        {
            return;
        }
        Type t = typeof(BuffManager);//括号中的为所要使用的函数所在的类的类名。

        if (Func.Contains(":"))
        {
            MethodInfo mt = t.GetMethod(Func.Split(':')[0]);
            if (mt == null)
            {
                Debug.Log("No Function: " + Func);
            }
            mt.Invoke(null, new object[] { mono, buffID, Func.Split(':')[1] });
        }
        else
        {
            MethodInfo mt = t.GetMethod(Func);
            if(mt == null)
            {
                Debug.Log("No Function: "+ Func);
            }
            mt.Invoke(null, new object[] { mono, buffID, "" });
        }
    }
    /// <summary>
    /// Buff生效SceneMono
    /// </summary>
    public void BuffAffect(SceneMonoData sceneMono, int buffID)
    {
        string Func = Data.Instance.TableAgent.GetString("AllBuff", buffID.ToString(), "FuncScene");
        if (Func == "")
        {
            return;
        }
        Type t = typeof(BuffManager);//括号中的为所要使用的函数所在的类的类名。

        if (Func.Contains(":"))
        {
            MethodInfo mt = t.GetMethod(Func.Split(':')[0]);
            if (mt == null)
            {
                Debug.Log("No Function: " + Func);
            }
            mt.Invoke(null, new object[] { sceneMono, buffID, Func.Split(':')[1] });
        }
        else
        {
            MethodInfo mt = t.GetMethod(Func);
            if (mt == null)
            {
                Debug.Log("No Function: " + Func);
            }
            mt.Invoke(null, new object[] { sceneMono, buffID, "" });
        }
    }
    /// <summary>
    /// Buff特效
    /// </summary>
    private void AddEffectMono(string effect, Mono mono, int buffID)
    {
        if (effect == "")
        {
            return;
        }
        GameObject clone = ResourceManager.Instance.Instantiate("Prefabs/Effects/" + effect);
        GameObject parent = GameMgr.Get<IMonoManager>().GetObj(mono);
        clone.transform.position = parent.transform.position;
        clone.transform.parent = parent.transform.Find("Sprite/Buff");
        var em = clone.GetComponent<ParticleSystem>().emission;
        em.enabled = true;
        GameMgr.Get<ITimeManager>().RgstTimeAction(GameMgr.Get<IMonoManager>().GetObj(mono).GetComponent<MonoBase>(), GameMgr.Get<IBuffManager>().GetInitBuff(mono, buffID, 1).buffTime.LastingTime + 5, () => { clone.GetComponent<Recycler>().LateDestroy(0); });
    }

    /// <summary>
    /// 爆炸
    /// </summary>
    public void Explosion(MonoAttribute attr, Vector3 Pos, string Explode)
    {
        GameObject clone = ResourceManager.Instance.Instantiate("Prefabs/CreatedSceneMono/" + Explode);
        int i = 0;
        clone.name = Explode + " (0)";
        string name = clone.name;
        while (GameMgr.Get<ISceneMonoManager>().GetAllSceneMono()._sceneMonoDatas.ContainsKey(name))
        {
            i++;
            name = name.Split('(')[0].Split(' ')[0] + "(" + i + ")";
        }
        clone.name = name;
        clone.transform.position = Pos;
        clone.GetComponent<SceneMonoBase>().NotStartOnScene = true;
        clone.GetComponent<SceneMonoBase>().Init(Pos, attr);
    }
    public void BreakAIce(Vector3 Pos, string Ice, MonoBase monoBase)
    {
        GameObject clone = ResourceManager.Instance.Instantiate("Prefabs/CreatedSceneMono/" + Ice);
        int i = 0;
        clone.name = Ice + " (0)";
        string name = clone.name;
        while (GameMgr.Get<ISceneMonoManager>().GetAllSceneMono()._sceneMonoDatas.ContainsKey(name))
        {
            i++;
            name = name.Split('(')[0].Split(' ')[0] + "(" + i + ")";
        }
        clone.name = name;
        clone.transform.position = Pos;
        clone.GetComponent<SceneMonoBase>().NotStartOnScene = true;
        clone.GetComponent<SceneMonoBase>().Init(Pos, MonoAttribute.Ice);
        if (monoBase != null)
        {
            clone.GetComponent<IceWall>().monoBase = monoBase;
        }
    }

    public static void Empty(Mono mono, int buffID, string param)
    {
        GameMgr.Get<IMonoManager>().ChangeHPValue(mono, -int.Parse(param));
    }
    public static void Burining(Mono mono, int buffID, string param)
    {
        GameMgr.Get<IMonoManager>().ChangeHPValue(mono, ((mono.Attr == MonoAttribute.Fire) ? 1 : -1) * int.Parse(param.Split('|')[0]));

        if (mono.BuffList.ContainsKey(2))//和冰生成蒸汽
        {
            mono.BuffList.Remove(1);
            mono.BuffList.Remove(2);
            GameMgr.Get<IBuffManager>().AddBuff(mono, 5, 1);
            CoroutineManager.Instance.StartCoroutine(RamBurstShoot(MonoAttribute.Steam, "75_120", mono.Position, "NormalBall"));
        }
        else if (mono.BuffList.ContainsKey(5))//和蒸汽抵消
        {
            GameMgr.Get<IMonoManager>().JumpText(mono, "\n抵消", 4);
            mono.BuffList.Remove(1);
            mono.BuffList.Remove(5);
        }
        else if (mono.BuffList.ContainsKey(6))//和电暗爆
        {
            GameMgr.Get<IMonoManager>().JumpText(mono, "\n暗爆", 4);
            mono.BuffList.Remove(1);
            GameMgr.Get<IBuffManager>().Explosion(MonoAttribute.Dark, mono.Position, "Explosion1");
            CoroutineManager.Instance.StartCoroutine(RamShoot(MonoAttribute.Dark, 120, 360, 0, mono.Position, "NormalBall"));
        }
        else if (mono.BuffList.ContainsKey(7))//和油炎爆
        {
            GameMgr.Get<IMonoManager>().JumpText(mono, "\n炎爆", 6);
            mono.BuffList.Remove(7);
            GameMgr.Get<IBuffManager>().Explosion(MonoAttribute.Fire, mono.Position, "Explosion1");
            CoroutineManager.Instance.StartCoroutine(RamShoot(MonoAttribute.Fire, 120, 360, 0, mono.Position, "NormalBall"));
        }
        else
        {
            GameMgr.Get<IMonoManager>().JumpText(mono.Position, "\n" + ((mono.Attr == MonoAttribute.Fire) ? "免疫" : "") + "燃烧", Data.Instance.PrintColor[0]);
        }
    }
    public static void Freeze(Mono mono, int buffID, string param)
    {
        GameMgr.Get<IMonoManager>().ChangeHPValue(mono, ((mono.Attr == MonoAttribute.Ice) ? 1 : -1) * int.Parse(param.Split('|')[0]));

        if (mono.BuffList.ContainsKey(1))//和火生成蒸汽
        {
            mono.BuffList.Remove(1);
            mono.BuffList.Remove(2);
            GameMgr.Get<IBuffManager>().AddBuff(mono, 5, 1);
            CoroutineManager.Instance.StartCoroutine(RamBurstShoot(MonoAttribute.Steam, "75_120", mono.Position, "NormalBall"));
        }
        else if (mono.BuffList.ContainsKey(5))//和蒸汽冻结
        {
            mono.BuffList.Remove(2);
            mono.BuffList.Remove(5);
            if (mono.Attr == MonoAttribute.Ice)
            {
                GameMgr.Get<IMonoManager>().JumpText(mono, "\n免疫冻结", 1);
                return;
            }
            GameMgr.Get<IMonoManager>().JumpText(mono, "\n冻结", 4);
            GameMgr.Get<IBuffManager>().AddBuff(mono, 8, 1);
            GameMgr.Get<IBuffManager>().BreakAIce(mono.Position, "IceMono", GameMgr.Get<IMonoManager>().GetObj(mono).GetComponent<MonoBase>());
        }
        else if (mono.BuffList.ContainsKey(6))//和电冰爆
        {
            GameMgr.Get<IMonoManager>().JumpText(mono, "\n冰爆", 5);
            mono.BuffList.Remove(6);
            GameMgr.Get<IBuffManager>().Explosion(MonoAttribute.Ice, mono.Position, "Explosion1");
            CoroutineManager.Instance.StartCoroutine(RamShoot(MonoAttribute.Ice, 120, 360, 0, mono.Position, "NormalBall"));
        }
        else if (mono.BuffList.ContainsKey(7))//和油冻结
        {
            mono.BuffList.Remove(2);
            mono.BuffList.Remove(7);
            if (mono.Attr == MonoAttribute.Ice)
            {
                GameMgr.Get<IMonoManager>().JumpText(mono, "\n免疫冻结", 1);
                return;
            }
            GameMgr.Get<IMonoManager>().JumpText(mono, "\n冻结", 6);
            GameMgr.Get<IBuffManager>().AddBuff(mono, 8, 1);
            GameMgr.Get<IBuffManager>().BreakAIce(mono.Position, "IceMono", GameMgr.Get<IMonoManager>().GetObj(mono).GetComponent<MonoBase>());
        }
        else
        {
            GameMgr.Get<IMonoManager>().JumpText(mono.Position, "\n" + ((mono.Attr == MonoAttribute.Ice) ? "免疫" : "") + "寒冷", Data.Instance.PrintColor[1]);
        }
    }
    public static void Steam(Mono mono, int buffID, string param)
    {
        GameMgr.Get<IMonoManager>().ChangeHPValue(mono, ((mono.Attr == MonoAttribute.Steam) ? 1 : -1) * int.Parse(param.Split('|')[0]));

        if (mono.BuffList.ContainsKey(1))//和火抵消
        {
            GameMgr.Get<IMonoManager>().JumpText(mono, "\n抵消", 0);
            mono.BuffList.Remove(1);
            mono.BuffList.Remove(5);
        }
        else if (mono.BuffList.ContainsKey(2))//和冰冻结
        {
            mono.BuffList.Remove(2);
            mono.BuffList.Remove(5);
            if (mono.Attr == MonoAttribute.Ice)
            {
                GameMgr.Get<IMonoManager>().JumpText(mono, "\n免疫冻结", 1);
                return;
            }
            GameMgr.Get<IMonoManager>().JumpText(mono, "\n冻结", 1);
            GameMgr.Get<IBuffManager>().AddBuff(mono, 8, 1);
            GameMgr.Get<IBuffManager>().BreakAIce(mono.Position, "IceMono", GameMgr.Get<IMonoManager>().GetObj(mono).GetComponent<MonoBase>());
        }
        else if (mono.BuffList.ContainsKey(6))//和电生成油
        {
            mono.BuffList.Remove(5);
            mono.BuffList.Remove(6);
            GameMgr.Get<IBuffManager>().AddBuff(mono, 7, 3);
            CoroutineManager.Instance.StartCoroutine(RamBurstShoot(MonoAttribute.Oil, "75_120", mono.Position, "NormalBall"));
        }
        else if (mono.BuffList.ContainsKey(7))//和油抵消
        {
            GameMgr.Get<IMonoManager>().JumpText(mono, "\n抵消", 6);
            mono.BuffList.Remove(7);
            mono.BuffList.Remove(5);
        }
        else
        {
            GameMgr.Get<IMonoManager>().JumpText(mono.Position, "\n" + ((mono.Attr == MonoAttribute.Steam) ? "免疫" : "") + "致盲", Data.Instance.PrintColor[4]);
        }
    }
    public static void Electric(Mono mono, int buffID, string param)
    {
        GameMgr.Get<IMonoManager>().ChangeHPValue(mono, ((mono.Attr == MonoAttribute.Electric) ? 1 : -1) * int.Parse(param.Split('|')[0]));

        if (mono.BuffList.ContainsKey(1))//和火暗爆
        {
            GameMgr.Get<IMonoManager>().JumpText(mono, "\n暗爆", 4);
            mono.BuffList.Remove(1);
            mono.BuffList.Remove(6);
            GameMgr.Get<IBuffManager>().Explosion(MonoAttribute.Dark, mono.Position, "Explosion1");
            CoroutineManager.Instance.StartCoroutine(RamShoot(MonoAttribute.Dark, 120, 360, 0, mono.Position, "NormalBall"));
        }
        else if (mono.BuffList.ContainsKey(2))//和冰雷爆
        {
            GameMgr.Get<IMonoManager>().JumpText(mono, "\n雷爆", 1);
            mono.BuffList.Remove(2);
            GameMgr.Get<IBuffManager>().Explosion(MonoAttribute.Electric, mono.Position, "Explosion1");
            CoroutineManager.Instance.StartCoroutine(RamShoot(MonoAttribute.Electric, 120, 360, 0, mono.Position, "NormalBall"));
        }
        else if (mono.BuffList.ContainsKey(5))//和蒸汽生成油
        {
            mono.BuffList.Remove(5);
            mono.BuffList.Remove(6);
            GameMgr.Get<IBuffManager>().AddBuff(mono, 7, 3);
            CoroutineManager.Instance.StartCoroutine(RamBurstShoot(MonoAttribute.Oil, "75_120", mono.Position, "NormalBall"));
        }
        else if (mono.BuffList.ContainsKey(7))//和油生成火
        {
            mono.BuffList.Remove(7);
            mono.BuffList.Remove(6);
            GameMgr.Get<IBuffManager>().AddBuff(mono, 1, 1);
            CoroutineManager.Instance.StartCoroutine(RamBurstShoot(MonoAttribute.Fire, "75_120", mono.Position, "NormalBall"));
        }
        else
        {
            GameMgr.Get<IMonoManager>().JumpText(mono.Position, "\n" + ((mono.Attr == MonoAttribute.Electric) ? "免疫" : "") + "麻痹", Data.Instance.PrintColor[5]);
        }
    }
    public static void Oil(Mono mono, int buffID, string param)
    {
        GameMgr.Get<IMonoManager>().ChangeHPValue(mono, ((mono.Attr == MonoAttribute.Oil) ? 1 : -1) * int.Parse(param.Split('|')[0]));

        if (mono.BuffList.ContainsKey(1))//和火油爆
        {
            GameMgr.Get<IMonoManager>().JumpText(mono, "\n油爆", 0);
            mono.BuffList.Remove(1);
            GameMgr.Get<IBuffManager>().Explosion(MonoAttribute.Oil, mono.Position, "Explosion1");
            CoroutineManager.Instance.StartCoroutine(RamShoot(MonoAttribute.Oil, 120, 360, 0, mono.Position, "NormalBall"));
        }
        else if (mono.BuffList.ContainsKey(2))//和冰冻结
        {
            mono.BuffList.Remove(2);
            mono.BuffList.Remove(7);
            if (mono.Attr == MonoAttribute.Ice)
            {
                GameMgr.Get<IMonoManager>().JumpText(mono, "\n免疫冻结", 1);
                return;
            }
            GameMgr.Get<IMonoManager>().JumpText(mono, "\n冻结", 1);
            GameMgr.Get<IBuffManager>().AddBuff(mono, 8, 1);
            GameMgr.Get<IBuffManager>().BreakAIce(mono.Position, "IceMono", GameMgr.Get<IMonoManager>().GetObj(mono).GetComponent<MonoBase>());
        }
        else if (mono.BuffList.ContainsKey(5))//和蒸汽抵消
        {
            GameMgr.Get<IMonoManager>().JumpText(mono, "\n抵消", 4);
            mono.BuffList.Remove(7);
            mono.BuffList.Remove(5);
        }
        else if (mono.BuffList.ContainsKey(6))//和雷生成火
        {
            mono.BuffList.Remove(7);
            mono.BuffList.Remove(6);
            GameMgr.Get<IBuffManager>().AddBuff(mono, 1, 6);
            CoroutineManager.Instance.StartCoroutine(RamBurstShoot(MonoAttribute.Fire, "75_120", mono.Position, "NormalBall"));
        }
        else
        {
            GameMgr.Get<IMonoManager>().JumpText(mono.Position, "\n" + ((mono.Attr == MonoAttribute.Oil) ? "免疫" : "") + "缓慢", Data.Instance.PrintColor[6]);
        }
    }
    public static void Recover(Mono mono, int buffID, string param)
    {
        if (mono.Attr != MonoAttribute.Dark)
        {
            GameMgr.Get<IMonoManager>().ChangeHPValue(mono, int.Parse(param));
        }
        else
        {
            GameMgr.Get<IMonoManager>().ChangeHPValue(mono, -2 * int.Parse(param));
        }

        if (mono.BuffList.ContainsKey(1))//和火生成雷
        {
            mono.BuffList.Remove(1);
            GameMgr.Get<IBuffManager>().AddBuff(mono, 6, 3);
            CoroutineManager.Instance.StartCoroutine(RamBurstShoot(MonoAttribute.Electric, "90_180", mono.Position, "NormalBall"));
        }
        else if (mono.BuffList.ContainsKey(2))//和冰生成油
        {
            mono.BuffList.Remove(2);
            GameMgr.Get<IBuffManager>().AddBuff(mono, 7, 4);
            CoroutineManager.Instance.StartCoroutine(RamBurstShoot(MonoAttribute.Oil, "90_180", mono.Position, "NormalBall"));
        }
        else if (mono.BuffList.ContainsKey(5))//和蒸汽生成冰
        {
            mono.BuffList.Remove(5);
            GameMgr.Get<IBuffManager>().AddBuff(mono, 2, 3);
            CoroutineManager.Instance.StartCoroutine(RamBurstShoot(MonoAttribute.Ice, "90_180", mono.Position, "NormalBall"));
        }
        else if (mono.BuffList.ContainsKey(6))//和雷生成水
        {
            mono.BuffList.Remove(6);
            GameMgr.Get<IBuffManager>().AddBuff(mono, 5, 3);
            CoroutineManager.Instance.StartCoroutine(RamBurstShoot(MonoAttribute.Steam, "90_180", mono.Position, "NormalBall"));
        }
        else if (mono.BuffList.ContainsKey(7))//和油生成火
        {
            mono.BuffList.Remove(7);
            GameMgr.Get<IBuffManager>().AddBuff(mono, 1, 5);
            CoroutineManager.Instance.StartCoroutine(RamBurstShoot(MonoAttribute.Fire, "90_180", mono.Position, "NormalBall"));
        }

    }
    public static void DarkPower(Mono mono, int buffID, string param)
    {
        if (mono.Attr == MonoAttribute.Dark)
        {
            GameMgr.Get<IMonoManager>().ChangeHPValue(mono, int.Parse(param));
        }
        else if (mono.Attr == MonoAttribute.Shine)
        {
            GameMgr.Get<IMonoManager>().ChangeHPValue(mono, -int.Parse(param) * 2);
        }
        else
        {
            GameMgr.Get<IMonoManager>().ChangeHPValue(mono, -int.Parse(param));
        }

        if (mono.BuffList.ContainsKey(1))//和火生成油
        {
            mono.BuffList.Remove(1);
            GameMgr.Get<IBuffManager>().AddBuff(mono, 7, 4);
            CoroutineManager.Instance.StartCoroutine(RamBurstShoot(MonoAttribute.Oil, "90_180", mono.Position, "NormalBall"));
        }
        else if (mono.BuffList.ContainsKey(2))//和冰生成水
        {
            mono.BuffList.Remove(2);
            GameMgr.Get<IBuffManager>().AddBuff(mono, 5, 3);
            CoroutineManager.Instance.StartCoroutine(RamBurstShoot(MonoAttribute.Steam, "90_180", mono.Position, "NormalBall"));
        }
        else if (mono.BuffList.ContainsKey(5))//和蒸汽生成雷
        {
            mono.BuffList.Remove(5);
            GameMgr.Get<IBuffManager>().AddBuff(mono, 6, 3);
            CoroutineManager.Instance.StartCoroutine(RamBurstShoot(MonoAttribute.Electric, "90_180", mono.Position, "NormalBall"));
        }
        else if (mono.BuffList.ContainsKey(6))//和雷生成火
        {
            mono.BuffList.Remove(6);
            GameMgr.Get<IBuffManager>().AddBuff(mono, 1, 5);
            CoroutineManager.Instance.StartCoroutine(RamBurstShoot(MonoAttribute.Fire, "90_180", mono.Position, "NormalBall"));
        }
        else if (mono.BuffList.ContainsKey(7))//和油生成冰
        {
            mono.BuffList.Remove(7);
            GameMgr.Get<IBuffManager>().AddBuff(mono, 2, 3);
            CoroutineManager.Instance.StartCoroutine(RamBurstShoot(MonoAttribute.Ice, "90_180", mono.Position, "NormalBall"));
        }
    }
    public static void Frozen(Mono mono, int buffID, string param)
    {
        mono.monoRealtimeStatus.IsFrozen = int.Parse(param);
    }

    public static void BuriningScene(SceneMonoData SceneMono, int buffID, string param)
    {
        if (SceneMono.attr == MonoAttribute.Ice)//和冰生成蒸汽散开爆炸
        {
            CoroutineManager.Instance.StartCoroutine(RamBurstShoot(MonoAttribute.Steam, "45_75",  SceneMono.position, "NormalBall"));
        }
        else if (SceneMono.attr == MonoAttribute.Steam)//和蒸汽抵消
        {
            GameMgr.Get<IMonoManager>().JumpText(SceneMono.position, "\n抵消", Color.white);
        }
        else if (SceneMono.attr == MonoAttribute.Electric)//和电生成暗散开爆炸
        {
            CoroutineManager.Instance.StartCoroutine(RamShoot(MonoAttribute.Dark, 45, 360, 0, SceneMono.position, "NormalBall"));
        }
        else if (SceneMono.attr == MonoAttribute.Oil)//和油炎爆
        {
            GameMgr.Get<IBuffManager>().Explosion(MonoAttribute.Fire, SceneMono.position, "Explosion1");
            CoroutineManager.Instance.StartCoroutine(RamShoot(MonoAttribute.Fire, 80, 560, 0.05f, SceneMono.position, "NormalBall"));
        }
    }
    public static void FreezeScene(SceneMonoData SceneMono, int buffID, string param)
    {
        if (SceneMono.attr == MonoAttribute.Fire)//和火生成蒸汽散开爆炸
        {
            CoroutineManager.Instance.StartCoroutine(RamBurstShoot(MonoAttribute.Steam, "45_75", SceneMono.position, "NormalBall"));
        }
        else if (SceneMono.attr == MonoAttribute.Steam)//和蒸汽冻结
        {
            GameMgr.Get<IBuffManager>().BreakAIce(SceneMono.position, "IceWall", null);
        }
        else if (SceneMono.attr == MonoAttribute.Electric)//和电冰爆
        {
            GameMgr.Get<IBuffManager>().Explosion(MonoAttribute.Ice, SceneMono.position, "Explosion1");
            CoroutineManager.Instance.StartCoroutine(RamShoot(MonoAttribute.Ice, 80, 560, 0.05f, SceneMono.position, "NormalBall"));
        }
        else if (SceneMono.attr == MonoAttribute.Oil)//和油冻结
        {
            GameMgr.Get<IBuffManager>().BreakAIce(SceneMono.position, "IceWall", null);
        }
    }
    public static void SteamScene(SceneMonoData SceneMono, int buffID, string param)
    {
        if (SceneMono.attr == MonoAttribute.Ice)//和冰冻结
        {
            GameMgr.Get<IBuffManager>().BreakAIce(SceneMono.position, "IceWall", null);
        }
        else if (SceneMono.attr == MonoAttribute.Fire)//和火抵消
        {
            GameMgr.Get<IMonoManager>().JumpText(SceneMono.position, "\n抵消", Color.white);
        }
        else if (SceneMono.attr == MonoAttribute.Oil)//和油抵消
        {
            GameMgr.Get<IMonoManager>().JumpText(SceneMono.position, "\n抵消", Color.white);
        }
        else if (SceneMono.attr == MonoAttribute.Electric)//和电生成油散开爆炸
        {
            CoroutineManager.Instance.StartCoroutine(RamBurstShoot(MonoAttribute.Oil, "45_75", SceneMono.position, "NormalBall"));
        }
    }
    public static void ElectricScene(SceneMonoData SceneMono, int buffID, string param)
    {
        if (SceneMono.attr == MonoAttribute.Fire)//和火生成暗散开爆炸
        {
            CoroutineManager.Instance.StartCoroutine(RamShoot(MonoAttribute.Dark, 45, 360, 0, SceneMono.position, "NormalBall"));
        }
        else if (SceneMono.attr == MonoAttribute.Ice)//和冰生成雷暴
        {
            GameMgr.Get<IBuffManager>().Explosion(MonoAttribute.Electric, SceneMono.position, "Explosion1");
            CoroutineManager.Instance.StartCoroutine(RamShoot(MonoAttribute.Electric, 80, 560, 0.05f, SceneMono.position, "NormalBall"));
        }
        else if (SceneMono.attr == MonoAttribute.Steam)//和水生成油散开爆炸
        {
            CoroutineManager.Instance.StartCoroutine(RamBurstShoot(MonoAttribute.Oil, "45_75", SceneMono.position, "NormalBall"));
        }
        else if (SceneMono.attr == MonoAttribute.Oil)//和油生成火散开爆炸
        {
            CoroutineManager.Instance.StartCoroutine(RamBurstShoot(MonoAttribute.Fire, "45_75", SceneMono.position, "NormalBall"));
        }
    }
    public static void OilScene(SceneMonoData SceneMono, int buffID, string param)
    {
        if (SceneMono.attr == MonoAttribute.Fire)//和火生成油爆
        {
            GameMgr.Get<IBuffManager>().Explosion(MonoAttribute.Oil, SceneMono.position, "Explosion1");
            CoroutineManager.Instance.StartCoroutine(RamShoot(MonoAttribute.Oil, 80, 560, 0.05f, SceneMono.position, "NormalBall"));
        }
        else if (SceneMono.attr == MonoAttribute.Ice)//和冰冻结
        {
            GameMgr.Get<IBuffManager>().BreakAIce(SceneMono.position, "IceWall", null);
        }
        else if (SceneMono.attr == MonoAttribute.Steam)//和水抵消
        {
            GameMgr.Get<IMonoManager>().JumpText(SceneMono.position, "\n抵消", Color.white);
        }
        else if (SceneMono.attr == MonoAttribute.Electric)//和电生成火散开爆炸
        {
            CoroutineManager.Instance.StartCoroutine(RamBurstShoot(MonoAttribute.Fire, "45_75", SceneMono.position, "NormalBall"));
        }
    }
    public static void ShineScene(SceneMonoData SceneMono, int buffID, string param)
    {
        if (SceneMono.attr == MonoAttribute.None)//和无生成爆炸
        {
            GameMgr.Get<IBuffManager>().Explosion(MonoAttribute.None, SceneMono.position, "Explosion1");
        }
        else if (SceneMono.attr == MonoAttribute.Fire)
        {
            GameMgr.Get<IBuffManager>().Explosion(MonoAttribute.Fire, SceneMono.position, "Explosion1");
        }
        else if (SceneMono.attr == MonoAttribute.Ice)
        {
            GameMgr.Get<IBuffManager>().Explosion(MonoAttribute.Ice, SceneMono.position, "Explosion1");
        }
        else if (SceneMono.attr == MonoAttribute.Steam)
        {
            GameMgr.Get<IBuffManager>().Explosion(MonoAttribute.Steam, SceneMono.position, "Explosion1");
        }
        else if (SceneMono.attr == MonoAttribute.Electric)
        {
            GameMgr.Get<IBuffManager>().Explosion(MonoAttribute.Electric, SceneMono.position, "Explosion1");
        }
        else if (SceneMono.attr == MonoAttribute.Oil)
        {
            GameMgr.Get<IBuffManager>().Explosion(MonoAttribute.Oil, SceneMono.position, "Explosion1");
        }
        CoroutineManager.Instance.StartCoroutine(RamBurstShoot(MonoAttribute.Shine, "45_75", SceneMono.position, "NormalBall"));
    }
    public static void DarkScene(SceneMonoData SceneMono, int buffID, string param)
    {
        if (SceneMono.attr == MonoAttribute.None)//和无生成爆炸
        {
            GameMgr.Get<IBuffManager>().Explosion(MonoAttribute.None, SceneMono.position, "Explosion1");
        }
        else if (SceneMono.attr == MonoAttribute.Fire)
        {
            GameMgr.Get<IBuffManager>().Explosion(MonoAttribute.Fire, SceneMono.position, "Explosion1");
        }
        else if (SceneMono.attr == MonoAttribute.Ice)
        {
            GameMgr.Get<IBuffManager>().Explosion(MonoAttribute.Ice, SceneMono.position, "Explosion1");
        }
        else if (SceneMono.attr == MonoAttribute.Steam)
        {
            GameMgr.Get<IBuffManager>().Explosion(MonoAttribute.Steam, SceneMono.position, "Explosion1");
        }
        else if (SceneMono.attr == MonoAttribute.Electric)
        {
            GameMgr.Get<IBuffManager>().Explosion(MonoAttribute.Electric, SceneMono.position, "Explosion1");
        }
        else if (SceneMono.attr == MonoAttribute.Oil)
        {
            GameMgr.Get<IBuffManager>().Explosion(MonoAttribute.Oil, SceneMono.position, "Explosion1");
        }
        CoroutineManager.Instance.StartCoroutine(RamBurstShoot(MonoAttribute.Dark, "45_75", SceneMono.position, "NormalBall"));
    }

    static IEnumerator RamShoot(MonoAttribute attribute, int AnglePlus, int AngleTotal, float Interval, Vector3 Pos, string BallType)
    {
        int AngleDefault = UnityEngine.Random.Range(0, AngleTotal);
        for (int Angle = 0; Angle < AngleTotal; Angle += AnglePlus)
        {
            yield return new WaitForSeconds(Interval);
            GameMgr.Get<ISkillManager>().BulletSkillAffect(
                BallType, Pos, Quaternion.Euler(0, 0, Angle + AngleDefault) * Vector2.one, 0.8f, attribute);
        }
    }
    static IEnumerator RamBurstShoot(MonoAttribute attribute, string AnglePlus, Vector3 Pos, string BallType)
    {
        yield return 0;
        int AngleDefault = UnityEngine.Random.Range(0, 360);
        for (int Angle = 0; Angle < 360; Angle += UnityEngine.Random.Range(int.Parse(AnglePlus.Split('_')[0]), int.Parse(AnglePlus.Split('_')[1])))
        {
            float Range = UnityEngine.Random.Range(1f, 3f);
            GameMgr.Get<ISkillManager>().BulletSkillAffect(
                BallType, Pos, Quaternion.Euler(0, 0, Angle + AngleDefault) * Vector2.one, 0.8f, attribute, Range);
        }
    }

    public static void AddMPCelling(Mono mono, int buffID, string param)
    {
        mono.MPData.MPCeiling += int.Parse(param);
    }
    public static void AddSpeed(Mono mono, int buffID, string param)
    {
        mono.Speed += float.Parse(param);
    }
    public static void AddDefaultAttckAdd(Mono mono, int buffID, string param)
    {
        mono.buffStatus.DefaultAttckAdd += int.Parse(param);
    }
    public static void AddAddAtrrNum(Mono mono, int buffID, string param)
    {
        mono.buffStatus.AddAtrrNum += int.Parse(param);
    }
    public static void AddMPRecover(Mono mono, int buffID, string param)
    {
        mono.MPData.RecoverSpeed += int.Parse(param);
    }
    public static void AddBuffAttrLastTime(Mono mono, int buffID, string param)
    {
        mono.buffStatus.BuffAttrLastTime += float.Parse(param);
    }
    public static void AddHpRecover(Mono mono, int buffID, string param)
    {
        mono.HPData.RecoverSpeed += int.Parse(param);
    }

}

public class Buff
{
    /// <summary>
    /// BuffID
    /// </summary>
    public int BuffID;

    /// <summary>
    /// Buff函数
    /// </summary>
    public string BuffEffect;

    /// <summary>
    /// Buff叠加层数
    /// </summary>
    public BuffOverride buffOverride = new BuffOverride();

    /// <summary>
    /// Buff结束时间
    /// </summary>
    public BuffTime buffTime = new BuffTime();
}
public class BuffTime
{
    public float LastingTime = 0;
    public float CurrentTime = 0;
}
public class BuffOverride
{
    public int MaxOverride = 0;
    public int CurrentOverride = 0;
}

